<?php

namespace App\Admin\Grid\Tools;

use App\Admin\Grid;

class ExportButton extends AbstractTool
{
    /**
     * ExportButton constructor.
     * @param Grid $grid
     */
    public function __construct(Grid $grid)
    {
        $this->grid = $grid;
    }

    /**
     * @return string
     */
    public function render()
    {
        if (!$this->grid->allowExport()) {
            return '';
        }

        $page = request('_page', 1);

        return <<<HTML

<ul class="layui-nav admin-dropdown">
    <li class="layui-nav-item">
        <a href="javascript:void(0);" class="layui-btn layui-btn-sm">导出</a>
        <dl class="layui-nav-child">
            <dd>
                <a href="/{$this->grid->exportUrl('all')}" target="_blank">所有记录</a>
            </dd>
            <dd>
                <a href="/{$this->grid->exportUrl('page', $page)}" target="_blank">本页记录</a>
            </dd>
            <dd>
                <a href="/{$this->grid->exportUrl('selected', '__rows__')}" target="_blank" class='_export-selected'>所选记录</a>
            </dd>
        </dl>
    </li>
</ul>

HTML;

    }
}
